import 'dart:async';
import 'dart:io';
import 'dart:isolate';

/// stream 与 多线程 FD资源开辟问题
void main() {

  print("main begin");
  StreamController controller = StreamController();
  Isolate.spawn(newThread,controller);

  controller.stream.listen((msg) {
    print("接收到子线程消息：$msg");
  });
  // sleep(Duration(seconds: 2));
  // controller.sink.add("你好，这里是子线程消息");
  print("main end");

}

void newThread(StreamController controller){
  sleep(Duration(seconds: 3));
  controller.sink.add("你好，这里是子线程消息");
}